pp108 : Migrating Libraries to Type Libraries

Migrating Libraries to Type Libraries

This topic presents an overview of the migration of Process Platform Libraries to Type Libraries.

The Process Platform Ajax Toolkit uses Libraries or Type Libraries (a Process Platform proprietary technology) in order to avoid the overhead of repeated loading of the same JavaScript files in a browser in which multiple pages are loaded.

By converting to Type Libraries, a developer can extend Libraries using inheritance.

Guidelines for Migration

The following are the guidelines for converting Process Platform Libraries to Type Libraries:

  • Each Library is modeled as a JScript Class, and the public methods are defined as prototype methods. To make a class public, use the setPublic(oClassName, oNamespace) instead of the setBehavior(oclassName) method. The namespace of the setPublic(oClassName, oNamespace) method refers to the library's URL from which the /cordys prefix and the .htm postfix are removed, and all slashes are replaced by dots. The oNamespace parameter makes it possible to use different classes with the same name that are available at different locations.
  • Convert attachLibrary(oHTML) into a static function on the libraries public method: oClass.attachType(oHTML).
  • Convert detachLibrary(oHTML) into a static function on the libraries public method: oClass.detachType(oHTML).

Example

Consider the conversion of the Tabs library to a Type Library. The unconverted sample code is as follows:

<HTML><HEAD><SCRIPT> setBehavior(TabControl) function attachLibrary(object) { //initialization code //Typically initializations to be done for the Object that is getting bound. } function detachLibrary(object) { //finalization code //garbage collection for the object } function TabControl() { } TabControl.prototype.setTile = function (value) { //code for set tile function } function fireTabLoadEvent (tabControl, tabId) { var customEvent = new Object(); customEvent.tabId = tabId; tabControl.raiseEvent("ontabload", customEvent); } TabControl.prototype.getTab = function (tabId) { var tabPage =this.document.createElement(""); ... fireTabLoadEvent(this,tabId); ... } </SCRIPT></HEAD><BODY></BODY></HTML>


The converted code is as follows:

<HTML><HEAD><SCRIPT> setPublic(TabControl, "wcp.library.ui"); function TabControl() { } function TabControl.attachType(object) { //initialization code //Typically initializations to be done for the Object that is getting bound. } function TabControl.detachType(object) { //finalization code //garbage collection for the object } TabControl.prototype.setTile = function (value) { //code for set tile function } function fireTabLoadEvent (tabControl, tabId) { var customEvent = new Object(); customEvent.tabId = tabId; tabControl.raiseEvent("ontabload", customEvent); } TabControl.prototype.getTab = function (tabId) { var tabPage =this.document.createElement(""); ... fireTabLoadEvent(this,tabId); ... } </SCRIPT></HEAD><BODY></BODY></HTML>

Notice that in the converted code, the constructor is declared before the attachType() and detachType() methods.